package com.hyl.message.controller;

import com.alibaba.fastjson.JSONObject;
import com.hyl.message.service.ProducerService;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * @author leaf
 * @description TODO
 * @created 2023/7/20
 */
@RestController
@RequestMapping("/message")
public class MessageController {
    @Resource
    private ProducerService producerService;

    /**
     * 发送消息
     * @param jsonObject
     * @return
     */
    @PostMapping("/send")
    public boolean send(@RequestBody JSONObject jsonObject){
        return producerService.messageSend(jsonObject);
    }

    /**
     * 发送消息
     * @param jsonObject
     * @return
     */
    @PostMapping("/sendSimple")
    public boolean sendSimple(@RequestBody JSONObject jsonObject){
        return producerService.messageSendSimple(jsonObject);
    }


    /**
     * 发送消息:订阅分发
     * @param jsonObject
     * @return
     */
    @PostMapping("/sendSub")
    public boolean sendSub(@RequestBody JSONObject jsonObject){
        return producerService.messageSendSub(jsonObject);
    }
    /**
     * 发送消息
     * @param jsonObject
     * @return
     */
    @PostMapping("/sendWork")
    public boolean sendWork(@RequestBody JSONObject jsonObject){
        for (int i = 0; i < 10; i++) {
            jsonObject.put("key",i);
            producerService.messageSendWork(jsonObject);
        }
        return true;
    }
}
